﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;

namespace WindowsFormsApp7
{
    public partial class Form1 : Form
    {
        private delegate  void MyDelegate();
        public Form1()
        {
            InitializeComponent();
        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                Task task_baidu = new Task(() => { Search_baidu("http://www.baidu.com/s?wd=" + searchBox.Text); });
                Task task_bing = new Task(() => { Search_bing("https://cn.bing.com/search?form=MOZTSB&pc=MOZI&q=" + searchBox.Text); });
                task_baidu.Start();
                task_bing.Start();
            }
            catch (Exception) { }
        }
       
        private void Search_baidu(string url)           // baidu
        {
            WebClient webClient = new WebClient();
            byte[] data = webClient.DownloadData(url);
            string response = Encoding.UTF8.GetString(data);
            BeginInvoke(new MyDelegate(() => { baiduBox.Text = response.Substring(0, 200); }));
        }
        private void Search_bing(string url)           // bing
        {
            WebClient webClient = new WebClient();
            byte[] data = webClient.DownloadData(url);
            string response = Encoding.UTF8.GetString(data);
            BeginInvoke(new MyDelegate(() => { bingBox.Text = response.Substring(0, 200); }));
        }

    }
}
